package com.heima.controller;
import com.heima.pojo.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

@Controller
public class HelloController {
    @GetMapping("/basic")
    public String basic(Model model) {
        //String数据
        model.addAttribute("name","黑马成勋原");
        //todo 对象数据
        Student student = new Student();
        student.setName("小明");
        student.setAge(20);
        student.setBirthday(new Date());
        student.setMoney(9000F);
        model.addAttribute("stu",student);
        //todo 找到页面
        return "01-basic";
    }

    @GetMapping("/list")
    public String list(Model model){
        //---------------------
        Student stu1 = new Student();
        stu1.setName("小李");
        stu1.setAge(18);
        stu1.setBirthday(new Date());
        stu1.setMoney(200.1f);
        //todo 小红对象模型数据
        Student stu2 = new Student();
        stu2.setName("小红");
        stu2.setAge(19);
        stu2.setMoney(200.1f);
        //todo 将两个对象模型数据存放到List集合中
        ArrayList<Student> stus = new ArrayList<>();
        stus.add(stu1);
        stus.add(stu2);
        //向model中存放List集合数据
        model.addAttribute("stus",stus);
        //------------------------------------

        //创建Map数据
        HashMap<String, Student> stuMap = new HashMap<>();
        stuMap.put("stu1",stu1);
        stuMap.put("stu2",stu2);
        // 3.1 向model中存放Map数据
        model.addAttribute("stuMap",stuMap);
        return "02-list";

    }
    @GetMapping("operation")
    public String testOperation(Model model) {
        //构建 Date 数据
        Date now = new Date();
        model.addAttribute("date1", now);
        model.addAttribute("date2", now);

        return "03-operation";
    }
}
